package hapi.log;

import Type;

class FirebugLogger extends BasicLogger {

	public function new() {
		super();
		if (! available()) throw "Firebug could not be detected";
	}
	
	public static function available() {
		return  haxe.Firebug.detect(); 
	}
	
	public override function log(message:Dynamic):Void {
		#if flash
			#if flash9
				message = message.split("\\").join("\\\\");
				flash.external.ExternalInterface.call("console.log", message);
			#elseif flash8
				message = message.split("\\").join("\\\\");
				flash.external.ExternalInterface.call("console.log", message);
			#else
				if( Std.is(message, String)) {
					message = message.split("\\").join("\\\\").split("'").join("\\'").split("\n").join("\\n").split("\r").join("\\r");
					message = StringTools.urlEncode(message);
				}
				var out = "javascript:console.log('"+message+"');";
				flash.Lib.getURL(out);
			#end
		#elseif js
			untyped console.log(message);
		#end
	}
}